package com.lhgray.sglhome.domain.usecase

import android.net.Uri
import com.freightoa.foundation.net.ApiResult
import com.freightoa.foundation.presentation.domain.BaseUseCase
import com.lhgray.sglhome.data.repository.UploadImageRepository
import javax.inject.Inject

class UploadPhotoUseCase @Inject constructor(private val uploadImageRepository: UploadImageRepository) :
    BaseUseCase() {
    suspend operator fun invoke(
        uris: List<Uri?>?,
        sourceTable: String,
        sourceId: String,
        editSubject: String,
        editDetail: String
    ): Result<Boolean> {
        val uploadPhoto =
            uploadImageRepository.uploadPhoto(uris, sourceTable, sourceId, editSubject, editDetail)
        return when (uploadPhoto) {
            is ApiResult.Error -> Result.failure(RuntimeException(uploadPhoto.message))
            is ApiResult.Exception<*> -> Result.failure(uploadPhoto.throwable)
            is ApiResult.Success -> Result.success(true)
        }


    }
}

